//ChinaDaily.java
package observer.oldmodel;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

/**
 *@author:youtubezou
 *@version:2012-7-30
 */
public class ChinaDaily implements Publisher {
	private ArrayList<Order> orders = new ArrayList<Order>();
	
	
	@Override
	public void attach(Order order) {
		orders.add(order);		
	}

	@Override
	public void detach(Order order) {
		orders.remove(order);
	}


	@Override
	public void notifyOrder() {
		int i = (int)(Math.random() * orders.size());
		
		orders.get(i).update(new Date() + "ChinaDaily published!");
	}

	@Override
	public void notifyOrders() {
		Iterator<Order> iter = orders.iterator();
		
		while(iter.hasNext()){
			iter.next().update(new Date() + "ChinaDaily published!");
		}
	}
	
}
